package com.seo.controller.proxy.transaction;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;
import com.seo.function.PageTool;
import com.seo.service.keyword.sdk.KeywordService;
import com.seo.service.proxy.sdk.BillProxyService;
import com.seo.utils.ClientConst;
import com.seo.utils.Jurisdiction;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: BillController
 * @author rtc
 * @version 2018.07.28 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "proxy/bill/")
public class BillProxyController {

	@Resource(name = "billProxyService")
	private BillProxyService billProxyService;

	@Resource(name = "keywordService")
	private KeywordService keywordService;

	@Autowired
	private PageTool pageTool;

	/**
	 * 余额明细
	 * 
	 * @param params
	 *            params
	 * @param request
	 *            request
	 * @return String
	 */
	@RequestMapping(value = "/balance")
	public String balanceList(@RequestParam Map<String, Object> params, HttpServletRequest request) throws Exception {
		log.info("余额明细");
		Integer userId = Jurisdiction.getT("id", Integer.class, ClientConst.SESSION_PROXY_USER);
		params.put("proxyUserId", userId);
		PageInfo<?> page = pageTool.getAutoPage(billProxyService::getProxyBalanceList, params);
		request.setAttribute("page", page);
		request.setAttribute("param", params);
		return "proxy/transaction/balance_list";
	}

	/**
	 * 关键词扣费列表
	 * 
	 * @param params
	 *            params
	 * @param request
	 *            request
	 * @return String
	 */
	@RequestMapping(value = "/keyWordDeduc")
	public String keyWordDeduc(@RequestParam Map<String, Object> params, HttpServletRequest request) throws Exception {
		log.info("关键词扣费记录");
		Integer userId = Jurisdiction.getT("id", Integer.class, ClientConst.SESSION_PROXY_USER);
		params.put("proxyUserId", userId);
		List<Map<String, Object>> engine = keywordService.getEngineList();
		PageInfo<?> page = pageTool.getAutoPage(billProxyService::getKeyWordDeducList, params);
		request.setAttribute("page", page);
		request.setAttribute("param", params);
		request.setAttribute("engine", engine);

		return "proxy/transaction/keyWord_deduc_list";
	}

}
